<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Modproduct extends MX_Controller{
    public function __construct(){
        parent::__construct();
    }
    public function index(){
        echo "Hello world!";
    }
    public function tags($name){
        $this->load->model(array("modproduct/mmodproduct_site_product"));
        $this->load->library(array("pagination"));
        $data['name'] = urldecode($name);
        
        $config['base_url'] = base_url("tags/$name.html/");
        $config['total_rows'] = $this->mmodproduct_site_product->countTagsData($data['name']);
        $config['per_page'] = 12;
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        
        $data['product_list'] = $this->mmodproduct_site_product->getTagsData($data['name'], $config['per_page'], (int)($this->uri->segment(3)));
        $this->load->view("modproduct/modproduct-tags", $data);
    }
    public function menu($menu){
        $this->load->model(array("modproduct/mmodproduct_site_product","modproduct/mmodproduct_site_product_menu"));
        $this->load->library(array("pagination"));
        if($menu && is_numeric($menu)){
            $data['menu_check'] = $this->mmodproduct_site_product_menu->getDataByID($menu);
            if($data['menu_check']){
                $config['base_url'] = base_url(_setURL($data['menu_check']['Name'])."-mproduct-".$data['menu_check']['ID'].".html");
                $config['total_rows'] = $this->mmodproduct_site_product->countMenuData($menu);
                $config['per_page'] = 12;
                $config['uri_segment'] = 2;
                $this->pagination->initialize($config);
                
                $data['product_list'] = $this->mmodproduct_site_product->getMenuData($menu, $config['per_page'], (int)($this->uri->segment(2)));
                $this->load->view("modproduct/modproduct-menu", $data);
            }
        }
    }
    public function groupMenu(){
        $this->load->model(array("modproduct/mmodproduct_site_product","modproduct/mmodproduct_site_product_menu"));
        $data['product_menu_list'] = $this->mmodproduct_site_product_menu->getPidData(0, "ASC", 99, 0);
        if($data['product_menu_list']){
            foreach($data['product_menu_list'] as $key=>$row){
                $data['product_menu_list'][$key]['product_list'] = $this->mmodproduct_site_product->getMenuData($row['ID'], 4, 0);
            }
            $this->load->view("modproduct/modproduct-groupMenu", $data);
        }
    }
    public function hot($record_number = 18, $record_start = 0){
        $this->load->model(array("modproduct/mmodproduct_site_product"));
        $data['product_list'] = $this->mmodproduct_site_product->getHotProduct($record_number, $record_start);
        if($data['product_list']){
            $this->load->view("modproduct/modproduct-hot", $data);
        }
    }
    public function allMenu(){
        $this->load->model(array("modproduct/mmodproduct_site_product_menu"));
        $data['menu_list'] = $this->mmodproduct_site_product_menu->getPidData(0, "ASC", 99, 0);
        if($data['menu_list']){
            $this->load->view("modproduct/modproduct-allMenu", $data);
        }
    }
    public function allProduct(){
        $this->load->model(array("modproduct/mmodproduct_site_product","modproduct/mmodproduct_site_product_menu"));
        $this->load->library(array("pagination"));
        
        $config['base_url'] = base_url("san-pham.html");
        $config['total_rows'] = $this->mmodproduct_site_product->countAllData();
        $config['per_page'] = 12;
        $config['uri_segment'] = 2;
        $this->pagination->initialize($config);
        
        $data['product_list'] = $this->mmodproduct_site_product->getAllData($config['per_page'], (int)($this->uri->segment(2)));
        $this->load->view("modproduct/modproduct-allProduct", $data);
    }
    public function detail($id=1){
        if($id && is_numeric($id)){
            $this->load->model(array("modproduct/mmodproduct_site_product"));
            $data['product_check'] = $this->mmodproduct_site_product->getDataByID($id);
            if($data['product_check']){
                $this->mmodproduct_site_product->addHit($id);
                $data['product_list'] = $this->mmodproduct_site_product->getSimilarData($data['product_check']['Menu'], $id, 6,0);
                $this->load->view("modproduct/modproduct-detail", $data);
            }
        }
    }
        
}